///
/// @ProjectName:    learning_rust
/// @Description:    
/// @File:           jz12.rs
/// @Author:         wujehy
/// @Email:          wujehy@qq.com
/// @Time:           2021-07-01 22:10
///
struct Solution{

}

impl Solution {
    fn new() -> Self {
        Solution{}
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param base double浮点型
     * @param exponent int整型
     * @return double浮点型
     */
    #[allow(non_snake_case)]
    pub fn Power(&self, base: f64, exponent: i32) -> f64 {
        match exponent {
            0 => 1.0,
            1 => base*1.0,
            -1 => 1.0/base,
            _ => {
                if exponent % 2 == 0
                {
                    return self.Power(base*base, exponent / 2);
                }

                if exponent > 0{
                    return self.Power(base*base, exponent / 2)*base;
                }

                return self.Power(base*base, exponent / 2) / base;
            }
        }


    }
}

#[test]
fn test12(){
    let s = Solution::new();
    let expect = 8.0;
    let result = s.Power(2.000, 3 );
    assert_eq!(expect, result);
    println!("data : {} ", result);
}